<?php
class CliStatisticController extends BpfController
{
  public function dateflowersCLI()
  {
    $mysqlModel = $this->getModel('mysql');
    //获取昨日的开始时间戳
    $starttime = mktime(0, 0, 0, date('m'), date('d') -1 , date('Y'));
    $endtime = $starttime + 86400;
    return $mysqlModel->query(join(' ', [
      'INSERT IGNORE INTO `players_flowers_statistics` (`date`, `week`, `flowers`, `player_id`)',
      ' SELECT',
      ' from_unixtime(`players_flowers_logs`.`created`, "%Y%m%d") AS `date`,',
      ' YEARWEEK(from_unixtime(`players_flowers_logs`.`created`, "%Y-%m-%d"), 1) AS `week`,',
      ' SUM(`players_flowers_logs`.`flowers`) AS `flowers`, `player_id`',
      ' FROM `players_flowers_logs`',
      " WHERE `players_flowers_logs`.`created` BETWEEN ${starttime} AND ${endtime}",
      ' GROUP BY `date`, `player_id`',
    ]));
  }
}
